<?php

declare (strict_types = 1);

namespace app\store\service\user;

use app\common\service\BaseService;
use app\store\model\user\PointsLog;


class Points extends BaseService
{
   public function getLog($params):array
   {
       $userCondition = [];
        if(!empty($params['search'])){
            $userCondition[] = ['user.nick_name|user.username|user.mobile','like',"%{$params['search']}%"];
        }

       $condition = [];
        if(!empty($params['start_time']) && !empty($params['end_time'])){
            $condition[] = ['start_time','>=',date('Y-m-d 00:00:00')];
            $condition[] = ['end_time','<=',date('Y-m-d 23:59:59')];
        }

        if(!empty($params['scene'])){
            $condition[] = ['scene','=',$params['scene']];
        }

        return (new PointsLog())
            ->with(['user.avatar'])
            ->where($condition)
            ->hasWhere('user',$userCondition)
            ->paginate($params['limit'] ?? 15)
            ->toArray();


   }


}
